package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.mall.MallShowCategoryReadDao;
import com.party.core.dao.write.mall.MallShowCategoryWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.mall.MallShowCategory;
import com.party.core.model.mall.MallShowCategoryQuery;
import com.party.core.service.mall.IMallShowCategoryService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * 展示商品类型实现
 * Created by wei.li
 *
 * @date 2017/8/24 0024
 * @time 15:23
 */
@Service
public class MallShowCategoryService implements IMallShowCategoryService {

    @Autowired
    private MallShowCategoryReadDao mallShowCategoryReadDao;

    @Autowired
    private MallShowCategoryWriteDao mallShowCategoryWriteDao;

    /**
     * 新增
     * @param mallShowCategory 商品类型
     * @return 编号
     */
    @Override
    public String insert(MallShowCategory mallShowCategory) {
        BaseModel.preInsert(mallShowCategory);
        boolean result = mallShowCategoryWriteDao.insert(mallShowCategory);
        if (result){
            return mallShowCategory.getId();
        }
        return null;
    }

    /**
     * 更新
     * @param mallShowCategory 类型
     * @return 更新结果（true/false）
     */
    @Override
    public boolean update(MallShowCategory mallShowCategory) {
        return mallShowCategoryWriteDao.update(mallShowCategory);
    }

    /**
     * 逻辑删除
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return mallShowCategoryWriteDao.deleteLogic(id);
    }

    /**
     * 物理删除
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return mallShowCategoryWriteDao.delete(id);
    }

    /**
     * 批量逻辑删除
     * @param ids 主键集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return mallShowCategoryWriteDao.batchDeleteLogic(ids);
    }

    /**
     * 批量物理删除
     * @param ids 主键集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return mallShowCategoryWriteDao.batchDelete(ids);
    }

    /**
     * 获取
     * @param id 主键
     * @return 展示商品类型
     */
    @Override
    public MallShowCategory get(String id) {
        return mallShowCategoryReadDao.get(id);
    }

    /**
     * 分页查询
     * @param mallShowCategory 商品类型
     * @param page 分页信息
     * @return 列表
     */
    @Override
    public List<MallShowCategory> listPage(MallShowCategory mallShowCategory, Page page) {
        return mallShowCategoryReadDao.listPage(mallShowCategory, page);
    }

    /**
     * 所有列表
     * @param mallShowCategory 商品类型
     * @return 列表
     */
    @Override
    public List<MallShowCategory> list(MallShowCategory mallShowCategory) {
        return mallShowCategoryReadDao.listPage(mallShowCategory, null);
    }

    /**
     * 分页查询
     * @param mallShowCategoryQuery
     * @param page 分页参数
     * @return 列表数据
     */
    @Override
    public List<MallShowCategory> queryListPage(MallShowCategoryQuery mallShowCategoryQuery, Page page) {
        return mallShowCategoryReadDao.queryListPage(mallShowCategoryQuery, page);
    }

    @Override
    public void deleteByTemplateId(String templateId) {
        mallShowCategoryWriteDao.deleteByTemplateId(templateId);
    }

    @Override
    public void deleteBySubjectId(String subjectId) {
        mallShowCategoryWriteDao.deleteBySubjectId(subjectId);
    }

    @Override
    public List<MallShowCategory> findByTemplateId(String templateId) {
        MallShowCategory mallShowCategory = new MallShowCategory();
        mallShowCategory.setTemplateId(templateId);
        return mallShowCategoryReadDao.listPage(mallShowCategory, null);
    }

    @Override
    public List<MallShowCategory> batchList(@NotNull Set<String> ids, MallShowCategory mallShowCategory, Page page) {
        return null;
    }
}
